Learn R Programming

GISTools (version 1.0-1)

Point in Polygon Counts: Number of Points in Each Polygon

Description

Given a set of points, and a set of polygons, computes the number of points in each polygon.

Usage

poly.counts(pts, polys)

Value

A list of integers of the same length as the number of polygons in polys, giving the number of points from pts.

Arguments

pts

A SpatialPoints or SpatialPointsDataFrame sf - POINT object .

polys

A SpatialPolygons or SpatialPolygonsDataFrame or sf -POLYGON or - MULTIPOLYGON object.

Author

Chris Brunsdon, Binbin Lu

Examples

Run this code
# Data for New Haven to use in example
data(newhaven)
# How many breaches of peace in each census block?
n.breach = poly.counts(breach,blocks)
blocks@data$Count.per <- n.breach/poly.areas(blocks)
# Compute densities and map them
choropleth(blocks,"Count.per")

Run the code above in your browser using DataLab